
var mobileReg = /1[3-9]{1}[0-9]{9}/;
var number=/^[0-9]*$/
var shadow_la = document.querySelector('.shadow_la')
var onclicktrue=true
$('#but').click(function () {
    var price = $('#price').val();
    var date = $('#date').val();
    var purpose = $('#purpose').val();
    var phone = $('#phone').val();
    var explain = $('#explain').val();
    if (!price || price.length > 15) {
        layer.open({
            content: '输入有误，请重新输入借款金额', skin: 'msg', time: 4
        });
        return false;
    }
    if (!date) {
        layer.open({
            content: '输入有误，请重新输入借款期限', skin: 'msg', time: 4
        });
        return false;
    }
    if (!purpose) {
        layer.open({
            content: '输入有误，请重新输入借款用途', skin: 'msg', time: 4
        });
        return false;
    }

    if (!phone||phone.length>11) {
        layer.open({
            content: '输入有误，请重新输入手机号码', skin: 'msg', time: 4
        });
        return false;
    }
    if(!number.test(price)||!number.test(date)){
        layer.open({
            content: '请输入数字', skin: 'msg', time: 4
        });
        return false;
    }
    if (!mobileReg.test(phone)) {
        layer.open({
            content: '手机号格式错误', skin: 'msg', time: 4
        });
        return false;
    }
    if(!onclicktrue){
        return
    }
    onclicktrue=false;
    $.ajax({
        url: 'https://api.youlijinfu.com/api/Borrow/SaveBorrow  ',
        type: 'POST', //GET
        async: true,
        data: {
            Price: price,
            Time: date,
            Use: purpose,
            Mobile: phone,
            Description: explain
        },
        timeout: 5000,
        dataType: 'json',
        success: function (data) {
            onclicktrue=true;
            shadow_la.style.display = 'block'
        },
        error: function (xhr, textStatus) {
            onclicktrue=true;
            alert('接口报错啦')
        }
    })
})
$('#btnqd').click(function () {
    $('#price').val('');
    $('#date').val('');
    $('#purpose').val('');
    $('#phone').val('');
    $('#explain').val('');
    shadow_la.style.display = 'none'
})


